﻿var LogTypeFlg = new Object(); 
var CallIVRInfo = new Object(); 

LogTypeFlg["Log"] = 0;
LogTypeFlg["ErrLog"] = 1;


function InitializeFolder()
{
	try
	{
		var MyFolderPath = LogFolderPath+FolderName;
		if(!Fso.FolderExists(MyFolderPath))
		{
			Fso.CreateFolder(MyFolderPath);
		}
		for (var key in week){
			MyFolderPath = LogFolderPath+FolderName+"\\"+week[key];
			if(!Fso.FolderExists(MyFolderPath))
			{
				Fso.CreateFolder(MyFolderPath);
			}
		}
	}
	catch(e)
	{
		return -999;
	}  
}

function WriteLog(ClassName, FunctionName, LogText, LogType, FileName)
{
	try
	{
		var today = new Date();
		var WriteDay = "";
		var WriteTime = "";
		if(today.getMonth()+1<=9){
			WriteDay = today.getYear()+'-0'+(today.getMonth()+1);
		}else{
			WriteDay = today.getYear()+'-'+(today.getMonth()+1);
		}
		if(today.getDate()<=9){
			WriteDay = WriteDay+'-0'+today.getDate();
		}else{
			WriteDay = WriteDay+'-'+today.getDate();
		}
		if(today.getHours()<=9){
			WriteTime = '0'+today.getHours()+":";
		}else{
			WriteTime = today.getHours()+":";
		}
		if(today.getMinutes()<=9){
			WriteTime = WriteTime+'0'+today.getMinutes()+":";
		}else{
			WriteTime = WriteTime+today.getMinutes()+":";
		}
		if(today.getSeconds()<=9){
			WriteTime = WriteTime+'0'+today.getSeconds();
		}else{
			WriteTime = WriteTime+today.getSeconds();
		}

//		alert(LogText);
//		alert(WriteDay.replace('-','').replace('-',''));

		//Fso = new ActiveXObject("Scripting.FileSystemObject");
		if(LogOn || ErrLogOn){
			
			InitializeFolder();
			
			var TxtFileStreamWriter;
			var MyLogFilePath = GetFolderWeek()+WriteDay.replace('-','').replace('-','')+"-"+FileName+'.txt';

			if(Fso.FileExists(MyLogFilePath))
			{
				TxtFileStreamWriter = Fso.OpenTextFile(MyLogFilePath,8);
			}else {
				TxtFileStreamWriter = Fso.OpenTextFile(MyLogFilePath,2,true);
			}

			var StrText = "["+WriteDay+" "+WriteTime+"] ";
			
			if(LogType==LogTypeFlg.Log)
			{
				//StrText = StrText+"[]";
			}
			if(LogType==LogTypeFlg.ErrLog)
			{
				StrText = StrText+"[★]";
			}
			StrText = StrText+"["+ClassName+"] ";
			StrText = StrText+"["+FunctionName+"] : "+LogText;

			TxtFileStreamWriter.Write(StrText);
			TxtFileStreamWriter.WriteBlankLines(1);
			TxtFileStreamWriter.Close();
			TxtFileStreamWriter = null;
		}

//		alert('OK');
	}
	catch(e)
	{
		//alert(e.message);
		return -999;
	}  
}

function GetFolderWeek()
{
	var today = new Date();
	var WeekDir='';
	switch (today.getDay()){
		case 1:
			WeekDir = "Mon";
			break;	
		case 2:
			WeekDir = "Tue";
			break;	
		case 3:
			WeekDir = "Wed";
			break;	
		case 4:
			WeekDir = "Thu";
			break;	
		case 5:
			WeekDir = "Fri";
			break;	
		case 6:
			WeekDir = "Sat";
			break;	
		case 0:
			WeekDir = "Sun";
			break;	
		default:
			break;	
	}

	var FolderWeekPath = LogFolderPath+FolderName+"\\"+WeekDir+"\\";
	return FolderWeekPath;
}

function GetDateString()
{
	try
	{
		var today = new Date();
		var WriteDay = "";
		var WriteTime = "";
		if(today.getMonth()+1<=9){
			WriteDay = today.getYear()+'-0'+(today.getMonth()+1);
		}else{
			WriteDay = today.getYear()+'-'+(today.getMonth()+1);
		}
		if(today.getDate()<=9){
			WriteDay = WriteDay+'-0'+today.getDate();
		}else{
			WriteDay = WriteDay+'-'+today.getDate();
		}
		if(today.getHours()<=9){
			WriteTime = '0'+today.getHours()+":";
		}else{
			WriteTime = today.getHours()+":";
		}
		if(today.getMinutes()<=9){
			WriteTime = WriteTime+'0'+today.getMinutes()+":";
		}else{
			WriteTime = WriteTime+today.getMinutes()+":";
		}
		if(today.getSeconds()<=9){
			WriteTime = WriteTime+'0'+today.getSeconds();
		}else{
			WriteTime = WriteTime+today.getSeconds();
		}	
		return WriteDay+' '+WriteTime;
		//return WriteDay.replace('-','').replace('-','')+WriteTime.replace(':','').replace(':','').replace(':','');
	}
	catch(e)
	{
		//alert(e.message);
		return -999;
	}  

} 

function   String.prototype.Trim()   {return   this.replace(/(^\s*)|(\s*$)/g,"");}   
function   String.prototype.Ltrim(){return   this.replace(/(^\s*)/g,   "");}   
function   String.prototype.Rtrim(){return   this.replace(/(\s*$)/g,   "");}   
var Fso = new ActiveXObject("Scripting.FileSystemObject");


function SplitParameter(Parameter)
{
	try
	{
        var Parameters = new Object();
        var items = new Array(); //定义一数组
        items = Parameter.split("&"); //字符分割
        
	    var MyArray = new Array(); 
        for(var i=0;i<items.length;i++) {
		    MyArray = items[i].split("="); 
            Parameters[MyArray[0]] = MyArray[1];
        }

        return Parameters;
	}
	catch(e)
	{
		return -999;
	}  
}


function ControlCollectionParameter(Parameters)
{
	try
	{
	    var Parameter = '';

	    for (var key in Parameters){
		    Parameter = Parameter+key+'='+Parameters[key]+'&';
	    }
        return Parameter.substring(0,Parameter.length-1);
	}
	catch(e)
	{
		return '';
	}  
}


function CollectionContainsParameter(Collection,Parameter)
{
	try
	{
		var ContainsReturn = false;
	    for (var key in Collection){
			if(Collection[key] == Parameter){
				ContainsReturn = true;
				break;
			}
	    }
        return ContainsReturn;
	}
	catch(e)
	{
		return false;
	}  
}


